package br.edu.ufcg.splab.util.commands;

import org.naturalcli.IParameterType;

public class PercentParameter implements IParameterType {
	
	/**
	 * {@inheritDoc}
	 */
	public String validationMessage(String value) {
		return this.validateParameter(value) ? null : value + " is not a percentage between 0 and 1.";
	}
	
	/**
	 * {@inheritDoc}
	 */
	public boolean validateParameter(String value) {
		try{
			double doubleRepresentation = Double.valueOf(value);
			return (doubleRepresentation > 0 && doubleRepresentation < 1 ? true : false);
		}catch(NumberFormatException e){
			return false;
		}
	}
	
	/**
	 * {@inheritDoc}
	 */
	public String getParameterTypeName() {
		return "percent0and1";
	}
	
	/**
	 * {@inheritDoc}
	 */
	public Object convertParameterValue(String value) {
		return Double.valueOf(value);
	}

}
